#include <REGX52.H>
#include "DS1302.h"
#include "LCD1602.h"
#include "Delay.h"

unsigned char position=0;

void Time_Change()
{
	if(P3_1==0)
	{
		Delay(20);
		while(P3_1==0);
		Delay(20);
		if(P3_0==0)
	{
		Delay(20);
		while(P3_0==0);
		Delay(20);
		position++;
		if(position>=7)
		{
			position=0;
		}
	}
		if(P3_2==0)
	{
		Delay(20);
		while(P3_2==0);
		Delay(20);
		DS1302[position]++;
	}
	if(P3_3==0)
	{
		Delay(20);
		while(P3_3==0);
		Delay(20);
		DS1302[position]--;
	}
	}
}

void main()
{
	LCD_Init();
	DS1302_Init();

	Write_Time();
	while(1)
	{
		if(P3_1==0)
	{
		Delay(20);
		while(P3_1==0);
		Delay(20);
		Timer_Init();
	}
		Read_Time();
		LCD_ShowNum(1,1,DS1302[0],2);
		LCD_ShowNum(1,4,DS1302[1],2);
		LCD_ShowNum(1,7,DS1302[2],2);
		LCD_ShowNum(1,10,DS1302[3],2);
		LCD_ShowNum(2,1,DS1302[4],2);
		LCD_ShowNum(2,4,DS1302[5],2);
		LCD_ShowNum(2,7,DS1302[6],2);
	}
}

void Timer0_Routinue() interrupt 1
{
	Timer_Change();
}